@ms-cloudpack/telemetry
A library for telemetry that gets reported to Application Insights by using Open Telemetry standards.
Currently, this library only supports Tracing. Metrics and Logs can be added later when needed.
Example usage
- Create a client:
const telemetryClient = new TelemetryClient({
serviceNamespace: 'cloudpack',
serviceName: 'cli',
productVersion: '1.2.3',
instrumentationKey: '<Application insights Instrumentation Key>',
logLevel: 'verbose',
});
- Add shared attributes
telemetryClient.setSharedSpanAttribute('sessionId', 'my-session-id');
These attributes will get added to all spans.
- Get the tracer
const tracer = telemetryClient.getTracer();
- Create a span / add events / end the span
const span = tracer.createSpan('my-unit-of-work');
span.addEvent('my-event', { myCustomAttribute: 'my-custom-value' });
try {
} catch (err) {
span.recordException(err);
}
span.end();
Lear more about spans
- Shutdown TelemetryClient before application exists
telemetryClient.shutdown();
- This will force flush all the remaining data to remote servers and prevent more data to be collected.
- Make sure that all spans have been ended before shuting down the telemetry client